<template>
  <div class="file-wrap">
    <form>
      <ul>
        <li><input id="singleUploadInput" name="file" type="file" /></li>
        <li><input @click="upload" type="submit" value="Upload" /></li>
      </ul>
    </form>
    <h3>imagesUrl:</h3>
    <h3>{{ imagesUrl }}</h3>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("admin");

export default {
  data() {
    return {
      imagesUrl: ""
    };
  },
  mounted() {},
  methods: {
    ...mapActions(["singleUpload"]),
    upload(e) {
      e.preventDefault();
      const formdata = new FormData();
      const input = document.getElementById("singleUploadInput");
      if (input.files && input.files[0]) {
        const file = input.files[0];
        formdata.set("name", file.name);
        formdata.set("file", file);
      }
      this.singleUpload(formdata).then(res => {
        this.imagesUrl = res.url;
      });
    },
  }
};
</script>

<style></style>
